<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <%@ include file="/WEB-INF/views/include/head.jsp"%> 
        <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
       
        <script src="${ctxStatic}/jquery-barcode/jquery-barcode.js" type="text/javascript"></script>
        <script type="text/javascript">
        var windowH = window.innerHeight
                        ||document.documentElement.clientHeight
                        ||document.body.clientHeight
                $('.middle').css('height',windowH - 40);
        $(document).ready(function(){
            $("#materialPlacement,#materialStyleCategory,#materialLevel,#materialSeason,#materialUnitCd,#materialUseType,#materialTypeCd").select2();
            $("#materialBarCodeDiv").empty().barcode($("#materialBarCode").val(), "code128",{barWidth:2, barHeight:30,showHRI:false});
           });
           //保存方法
        var saveForm={
                s:null,
                t:null,
                save:function(s,t){
                    //如果物料款式null 则等于''
                     if($("#materialStyleCategory").val()==null){
                         $("#materialStyleCategory").val('');
                     }
                    if($("#materialStyleCategory").val()!=""&&$("#materialStyleCategory").val()!=null){
                        if($("#materialStyleCategory").val().length>6){
                            // 选择物料款式过多！
                            layer.msg('<spring:message code="myMaterial_choosed_style_over"/>', {time:1000});
                            return;
                        }
                    }
                    if($("#materialPlacement").val()==null){
                        $("#materialPlacement").val('');
                    }
                    if($("#materialPlacement").val()!=""&&$("#materialPlacement").val()!=null){
                        if($("#materialPlacement").val().length>6){
                            // 选择物料部位过多！
                            layer.msg('<spring:message code="myMaterial_choosed_placement_over"/>', {time:1000});
                            return;
                        }
                    }
                    $(t).attr("disabled",true);
                    this.s=s;
                    this.t=t;
                          $("#inputForm").validate({
                              submitHandler: function() {
                                  // 格式化，去除逗号
                                  formUnFormat($("#inputForm"));
                                  var params = $("#inputForm").serialize();
                                     $.post("${ctx}/material/mymaterial/save",params,function(result){
                                          tipParent(result.message);
                                          if(result.statusCode==STATUSCODEOK){
                                              if(saveForm.s==1){
                                                  $("#inputForm")[0].reset();  
                                                  $(saveForm.t).attr("disabled",false);
                                                  $("#materialPlacement,#materialStyleCategory,#materialLevel,#materialSeason,#materialUnitCd,#materialUseType,#materialTypeCd").val('');
                                                  $("#materialPlacement,#materialStyleCategory,#materialLevel,#materialSeason,#materialUnitCd,#materialUseType,#materialTypeCd").select2();
                                               // 刷新页面
                                                  window.parent.frames[0].location.reload();
                                                  
                                              }else{
                                                  window.parent.frames[0].location.reload();
                                                  closeWin(); 
                                              }
                                            }else{
                                                $(saveForm.t).attr("disabled",false);
                                            }
                                       },'json'); 
                                  },
                               rules: {
                                  materialCode: {remote: "${ctx}/material/mymaterial/checkName?oldMaterialCode=" +$("#oldMaterialCode").val() },
                              },
                              messages: {
                                  //物料代码已存在
                                  materialCode: {remote: '<spring:message code="myMaterial_code_exist"/>'},
                              },
                              fail: function(element,e) {  
                                $(saveForm.t).attr("disabled",false);
                            }
                          });
                          $("#inputForm").submit(); 
                }
        }
        </script>
    </head>
    <body>
        <!--头部-->
        <div class="myshop clearfix">
            <c:choose>
                <c:when test="${myMaterial.id!=null&&myMaterial.id!=''}">
                    <!--编辑-->
                    <p class="myshoptop fl"><spring:message code="myMaterial_modifyMaterial"/></p>
                </c:when>
                <c:otherwise>
                    <!--新建-->
                    <p class="myshoptop fl"><spring:message code="myMaterial_createMaterial"/></p>
                </c:otherwise>
            </c:choose>
            <div class="fr">
                 <div class="topBtnClose" onclick="closeWin()">
                    <img src="${ctxStatic}/images/btn-close.png">
                </div>
            </div>
        </div>
        <form id="inputForm" method="post">
        <input type="hidden" id="id" name="id" value="${myMaterial.id}"/>
        <input type="hidden"  name="version" value="${myMaterial.version}"/>
        <input type="hidden" id="oldMaterialCode"  name="oldMaterialCode" value="${myMaterial.materialCode}"/>
        <c:set value="<%=ResourcesUtil.getConfig(\"material_Category\")%>" var="materialCategory" />
        <c:set value="<%=ResourcesUtil.getConfig(\"material_Unit\")%>" var="materialUnit" />
        <c:set value="<%=ResourcesUtil.getConfig(\"material_UseType\")%>" var="useType" />
        <c:set value="<%=ResourcesUtil.getConfig(\"material_season\")%>" var="season" />
        <c:set value="<%=ResourcesUtil.getConfig(\"material_styleCategory\")%>" var="styleCategory" />
        <c:set value="<%=ResourcesUtil.getConfig(\"material_placement\")%>" var="placement" />
        <c:set value="<%=ResourcesUtil.getConfig(\"material_level\")%>" var="level" />
            <div class="myshop_middle" style="height:455px;">
                <div class="data clearfix">
                    <div class="ch fl clearfix">
                        <div class="ch_middle fl haveToBox">
                            <!-- 物料编码 -->
                            <p class="data_id"><spring:message code="myMaterial_code"/></p>
                            <input type="text" class="form-control" name="materialCode" value="${myMaterial.materialCode}"  maxlength="22"  data-rule-required="true"   data-msg-required="<spring:message code="myMaterial_pleaseInput_materialCode"/>" data-rule-lettersnumbers="true"  data-msg-lettersnumbers="<spring:message code="myMaterial_pleaseInput_materialCode"/>" >
                            <p class="haveTo">*</p>
                        </div>
                        <div class="ch_middle fr haveToBox">
                            <!-- 物料类别 -->
                            <p class="data_id"><spring:message code="myMaterial_materialType"/></p>
                            <select class="sex" id="materialTypeCd" name="materialTypeCd"  data-rule-required="true"  data-msg-required="<spring:message code="myMaterial_pleaseChoosedMaterialType"/>">
                                <option value=""><spring:message code="myMaterial_pleaseChoosed"/></option>
                                <c:forEach items="${fns:getDictList(materialCategory)}"   var="category">
                                    <option  <c:if test="${fn:split(myMaterial.materialTypeCd,'-')[1] eq category.itemValue}">selected="selected"</c:if> value="${category.itemCode}-${category.itemValue}" > 
                                        ${category.itemName}
                                    </option>
                                </c:forEach>
                            </select>
                            <p class="haveTo">*</p>
                        </div>
                    </div>
                    <div class="ch fr">
                        <!-- 业务类别 -->
                           <p class="data_id"><spring:message code="myMaterial_businessType"/></p>
                           <div class="data_rd fl">
                            <c:forEach items="${fns:getDictList(useType)}"   var="type" varStatus="status">
                                <label class="lbst"><input type="radio" name="materialUseType" class="rast"  value="${type.itemCode}-${type.itemValue}" 
                                <c:if test="${status.index==0}">checked=checked</c:if>
                                <c:if test="${fn:split(myMaterial.materialUseType,'-')[1] eq type.itemValue}">checked=checked</c:if>
                                >${type.itemName}</label>
                            </c:forEach>
                        </div>
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl ">
                        <!-- 物料条形码 -->
                        <p class="data_id"><spring:message code="myMaterial_barCode"/></p>
                        <div class="fl txmBox" id="materialBarCodeDiv" ></div>
                        <!-- 生产条形码 -->
                        <input type="hidden" id="materialBarCode" name="materialBarCode" value="${myMaterial.materialBarCode}"> 
                    </div>
                    <div class="ch fr haveToBox">
                    <!-- 物料材质 -->
                        <p class="data_id"><spring:message code="myMaterial_texture"/></p>
                            <input type="text" class="form-control" name="materialComposition" value="${myMaterial.materialComposition}" maxlength="49"   data-msg-required="<spring:message code="myMaterial_pleaseInput_composition"/>" data-rule-required="true" >
                        <p class="haveTo">*</p>
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl haveToBox">
                    <!-- 中文名称 -->
                        <p class="data_id"><spring:message code="myMaterial_nameCn"/></p>
                            <input type="text" class="form-control" name="materialNameCn" value="${myMaterial.materialNameCn}" maxlength="49"     data-rule-required="true"  data-msg-required="<spring:message code="myMaterial_pleaseInput_materialNameCn"/>" >
                    <p class="haveTo">*</p>
                    </div>
                    <div class="ch fr haveToBox">
                    <!-- 英文名称 -->
                        <p class="data_id"><spring:message code="myMaterial_nameEn"/></p>
                            <input type="text" class="form-control" name="materialNameEn" value="${myMaterial.materialNameEn}"  maxlength="49"  data-rule-required="true"   data-msg-required="<spring:message code="myMaterial_pleaseInput_materialNameEn"/>">
                    <p class="haveTo">*</p>
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl haveToBox">
                    <!-- 物料规格 -->
                        <p class="data_id"><spring:message code="myMaterial_spec"/></p>
                           <input type="text" class="form-control" data-rule-banjiao="true" data-msg-banjiao="<spring:message code="myMaterial_pleaseInput_banjiao"/>" name="materialSpec" value="${myMaterial.materialSpec}" maxlength="49"   data-msg-required="<spring:message code="myMaterial_pleaseInput_materialSpec"/>" data-rule-required="true" >
                    <p class="haveTo">*</p>
                    </div>
                    <div class="ch fr haveToBox">
                    <!-- 物料单位 -->
                        <p class="data_id"><spring:message code="myMaterial_unit"/></p>
                            <select class="sex" id="materialUnitCd" name="materialUnitCd" data-rule-required="true" data-msg-required="<spring:message code="myMaterial_pleaseChoosedMaterialUnitCd"/>" >
                                <option value=""><spring:message code="myMaterial_pleaseChoosed"/></option>
                                <c:forEach items="${fns:getDictList(materialUnit)}"   var="unit">
                                    <option  <c:if test="${fn:split(myMaterial.materialUnitCd,'-')[1] eq unit.itemValue}">selected="selected"</c:if> value="${unit.itemCode}-${unit.itemValue}" > 
                                        ${unit.itemName}
                                    </option>
                                </c:forEach>
                            </select>
                            <p class="haveTo">*</p>
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl clearfix">
                        <!-- 物料等级 -->
                        <div class="data clearfix haveToBox">
                            <p class="data_id"><spring:message code="myMaterial_level"/></p>
                            <select class="sex" id="materialLevel" name="materialLevel" data-rule-required="true" data-msg-required="<spring:message code="myMaterial_pleaseChoosedMaterialLevel"/>" >
                                <option value=""><spring:message code="myMaterial_pleaseChoosed"/></option>
                                <c:forEach items="${fns:getDictList(level)}"   var="levels">
                                    <option  <c:if test="${fn:split(myMaterial.materialLevel,'-')[1] eq levels.itemValue}">selected="selected"</c:if> value="${levels.itemCode}-${levels.itemValue}" > 
                                        ${levels.itemName}
                                    </option>
                                </c:forEach>
                            </select>
                            <p class="haveTo">*</p>
                        </div>
                        <!-- 物料款式 -->
                        <div class="data clearfix">
                            <p class="data_id"><spring:message code="myMaterial_style"/></p>
                            <select class="sex mult" id="materialStyleCategory" multiple="multiple" name="materialStyleCategory">
                                <%-- <option value=""><spring:message code="myMaterial_pleaseChoosed"/></option> --%>
                                <c:forEach items="${fns:getDictList(styleCategory)}"   var="style">
                                     <option  value="${style.itemCode}-${style.itemValue}"
                                      <c:forEach items="${fn:split(myMaterial.materialStyleCategory,',')}" var="selectStyle" >
                                        <c:if test="${fn:split(selectStyle,'-')[1] eq style.itemValue}">selected="selected"</c:if>
                                       </c:forEach>
                                      > 
                                        ${style.itemName}
                                    </option> 
                                </c:forEach>
                            </select>
                        </div>
                        <div class="data clearfix">
                            <!-- 物料年份 -->
                            <div class="ch_middle fl clearfix haveToBox">
                                <p class="data_id"><spring:message code="myMaterial_year"/></p>
                                <input type="text" class="form-control" name="materialYear" value="${myMaterial.materialYear}" maxlength="4"   data-msg-required="<spring:message code="myMaterial_pleaseInput_year"/>" data-rule-required="true" data-rule-nonnegativeInteger="true"  data-msg-nonnegativeInteger="<spring:message code="myMaterial_pleaseInput_year"/>">
                            <p class="haveTo">*</p>
                            </div>
                            <div class=" ch_middle fr clearfix  haveToBox">
                            <!-- 物料季节 -->
                                <p class="data_id"><spring:message code="myMaterial_season"/></p>
                                <select class="sex" id="materialSeason" name="materialSeason" data-rule-required="true" data-msg-required="<spring:message code="myMaterial_pleaseChoosedMaterialSeason"/>" >
                                    <option value=""><spring:message code="myMaterial_pleaseChoosed"/></option>
                                    <c:forEach items="${fns:getDictList(season)}"   var="seasons">
                                        <option  <c:if test="${fn:split(myMaterial.materialSeason,'-')[1] eq seasons.itemValue}">selected="selected"</c:if> value="${seasons.itemCode}-${seasons.itemValue}" > 
                                             ${seasons.itemName}
                                        </option>
                                    </c:forEach>
                                </select>
                                <p class="haveTo">*</p>
                            </div>
                        </div>
                        <div class="data clearfix  haveToBox">
                        <!-- 物料颜色 -->
                            <p class="data_id"><spring:message code="myMaterial_color"/></p>
                            <input type="text" class="form-control" name="materialColor" value="${myMaterial.materialColor}" maxlength="50"   data-msg-required="<spring:message code="myMaterial_pleaseInput_materialColor"/>" data-rule-required="true" >
                        <p class="haveTo">*</p>
                        </div>
                        <div class="data clearfix">
                        <!-- 描述 -->
                            <p class="data_id"><spring:message code="myMaterial_remarks"/>
                            <span class="txtRg">(0/100)</span>
                            </p>
                            <div class="data_ip fl">
                                <textarea class="dsp"  name="remarks"  maxlength="100" value="${myMaterial.remarks}">${myMaterial.remarks}</textarea>
                            </div>
                        </div>
                    </div>
                    <div class="ch fr clearfix">
                        <div class="data clearfix haveToBox">
                        <!-- 物料克重-->
                        <p class="data_id "><spring:message code="myMaterial_materialGramWeight"/></p>
                            <input type="tel" class="form-control" name="materialGramWeight" value="<fmt:formatNumber value="${myMaterial.materialGramWeight}" pattern="#,#00.00#"/>" onblur="formatNumber(this)" onfocus="unFormat(this)" data-rule-maxlength="20"   data-msg-maxlength="<spring:message code="myMaterial_pleaseInput_materialGramWeight"/>"   data-msg-required="<spring:message code="myMaterial_pleaseInput_materialGramWeight"/>" data-rule-required="true" data-rule-integerDecimalmax="17.3"  data-msg-integerDecimalmax="<spring:message code="myMaterial_pleaseInput_materialGramWeight"/>">
                        <p class="haveTo">*</p>
                        </div>
                        <div class="data clearfix">
                        <!-- 物料部位 -->
                        <p class="data_id "><spring:message code="myMaterial_placement"/></p>
                            <select class="sex mult" id="materialPlacement" name="materialPlacement" multiple="multiple" >
                            <%-- <option value=""><spring:message code="myMaterial_pleaseChoosed"/></option> --%>
                                    <c:forEach items="${fns:getDictList(placement)}"   var="placements">
                                        <option  value="${placements.itemCode}-${placements.itemValue}"
                                           <c:forEach items="${fn:split(myMaterial.materialPlacement,',')}" var="selectPlacements" >
                                                   <c:if test="${fn:split(selectPlacements,'-')[1] eq placements.itemValue}">selected="selected"</c:if> 
                                           </c:forEach>
                                          > 
                                             ${placements.itemName}
                                        </option>
                                    </c:forEach>
                            </select>
                        </div>
                        <div class="ch_top clearfix">
                        <!-- 照片 -->
                            <p class="data_id"><spring:message code="myMaterial_pic"/></p>
                            <div class="square">
                                <!-- <div class="circle">
                                    <p class="add">+</p>
                                </div> -->
                                <!-- 上传图片 -->
                                <%-- <button type="button" class="bt_ip"><span class="ip_image"><spring:message code="myMaterial_uploadPic"/></span></button> --%>
                                <input type="hidden" name="fileId" value="${myMaterial.fileId}" >
                                <input  id="nameImage" type="hidden" name="filePath"  value="${myMaterial.uploadFile.showImgUrl}"  htmlEscape="false" maxlength="255" class="input-xlarge" data-msg-required="<spring:message code="myMaterial_img_url"/>" /> 
                                <sys:ckfinder input="nameImage" type="images" uploadPath="/custom" selectMultiple="false" maxWidth="100" maxHeight="100"/>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="twobtn" style="margin-top:5px;">
                <div class="onebtn clearfix">
                    <shiro:hasPermission name="material:mymaterial:edit">
                        <!-- 保存 -->
                        <button type="button" class="btn save fl"  onclick="saveForm.save(0,this)"><spring:message code="myMaterial_save"/></button>
                        <c:if test="${empty myMaterial.id}">
                            <!-- 保存并继续 -->
                            <button type="button" class="btn gon fr" onclick="saveForm.save(1,this)"><spring:message code="myMaterial_saveAndContinue"/></button>
                        </c:if>
                    </shiro:hasPermission>
                </div>
            </div>
        </form>
    </body>
</html>